﻿using System;
using System.Collections.Generic;
using System.Windows;

namespace Graphe.Windows.Controls.Collations
{
    public class CollationsControlStylePicker
    {
        private static Dictionary<string, bool> _existLookups = new Dictionary<string, bool>();
        private static Dictionary<string, object> _resourceDictionary = new Dictionary<string, object>();

        public static bool ResourceExists(string key)
        {
            if (_existLookups.ContainsKey(key))
            {
                return _existLookups[key];
            }
            else
            {
                object result = FindResource(key);
                if (result != null)
                {
                    _resourceDictionary.Add(key, result);
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        private static object FindResource(string key)
        {
            return Application.Current.TryFindResource(key);
        }

        public static object FindProperVersionResource(string key)
        {
            if(ResourceExists(key + CollationControl.ControlVersionId.ToString()))
                return FindResource(key + CollationControl.ControlVersionId.ToString());
            else
                return FindResource(key);
        }

    }
}
